package com.mucas;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class CourseExtractor {

	private InputStream in				= null;
	private Document doc				= null;
	private DocumentBuilderFactory dbf;
	private DocumentBuilder db;
	
	public CourseExtractor() {
		this.dbf = DocumentBuilderFactory.newInstance();
	}
	
	public boolean setDataStream(InputStream is) {
		if(is instanceof InputStream) {
			this.in = is;
			return true;
		} else {
			return false;
		}
	}
	
	public Document getDoc() {
		if(!(this.in instanceof InputStream))
			return null;
		
		try {
			this.db  = this.dbf.newDocumentBuilder();
			this.doc = this.db.parse(this.in);
			
		} catch(Exception e) {
			
			return null;
			
		}
		//this.doc.getDocumentElement().normalize();
		return doc;
	}
	
}
